﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using MQuery;

namespace SW.DDD.Application.Query
{
    /// <summary>
    /// 子实体查询
    /// </summary>
    /// <typeparam name="TView">结果视图</typeparam>
    /// <typeparam name="TSubEntity">子实体</typeparam>
    /// <typeparam name="TAggregateRoot">聚合根</typeparam>
    /// <typeparam name="TKey"></typeparam>
    public class SubsQuery<TView, TSubEntity, TAggregateRoot, TKey> : IQuery<(IEnumerable<TView> data, int? count)>
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="id">聚合根ID</param>
        /// <param name="subsSelector">子实体选择表达式</param>
        /// <param name="queryExpression">查询表达式</param>
        /// <param name="needCount">是否计数</param>
        public SubsQuery(
            TKey id,
            Expression<Func<TAggregateRoot, IEnumerable<TSubEntity>>> subsSelector,
            QueryExpression<TView> queryExpression, 
            bool needCount = false)
        {
            SubsSelector = subsSelector;
            QueryExpression = queryExpression;
            Id = id;
            NeedCount = needCount;
        }

        public TKey Id { get; }

        public Expression<Func<TAggregateRoot, IEnumerable<TSubEntity>>> SubsSelector { get; }

        public QueryExpression<TView> QueryExpression { get; }

        public bool NeedCount { get; }

        public IDictionary<string, object> Parameters { get; } = new Dictionary<string, object>();
    }
}
